package com.guang.syncronized_pro;

import com.guang.syncronized.ObjectAgeTest;
import org.openjdk.jol.info.ClassLayout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.TimeUnit;

/**
 * @Description 测试偏向锁在偏向的时候才会置为0
 * @Author liguang
 * @Date 2022/10/20/13:50
 */
public class SyncronizedProThree {
    private final static Logger logger = LoggerFactory.getLogger(SyncronizedProThree.class);
    public static void main(String[] args) throws InterruptedException {

        TimeUnit.SECONDS.sleep(5);

        Object lock = new Object();
        logger.info("当前偏向锁是可偏向的，101，但是没有偏向的线程ID");
        logger.info("当前对象头的状态是：{}",ClassLayout.parseInstance(lock).toPrintable());
        new Thread(()->{
            logger.info("当前偏向锁是可偏向的，101，已经有了偏向的线程ID");
            synchronized (lock){
                logger.info("当前对象头的状态是：{}",ClassLayout.parseInstance(lock).toPrintable());
            }
        },"t1").start();

        new Thread(()->{

        },"t2").start();
    }
}
